import { SetStateAction, useRef, useState } from 'react'
import { postCompanyInfoDetailBrandInfoPageList } from '@/api/companyDetail/intellectual-property'
import { useNewPage } from '@hs-admin/utils'
import { HsAdminTablePage } from '@hs-admin/base-components'
import { DetailModal } from '@hs-server/components'

const Patent = (props: any) => {
  const { companyCode, hiddenModule } = props
  const columns = [
    {
      title: '序号',
      dataIndex: 'index',
      width: 80,
      render: (_: string, _record: any, index: number) => <>{index + 1 + (pagination.current - 1) * pagination.pageSize}</>
    },
    {
      title: '商标图案',
      dataIndex: 'photourl',
      render: (text: string) => <img src={text} style={{ width: '48px', height: '48px' }} alt="" />
    },
    {
      title: '商标名称',
      dataIndex: 'brandName',
      render: (text: string, record: any) => (
        <span
          className="link cursor-pointer"
          onClick={() => {
            record.eventSubType = '知识产权'
            record.eventSegment = '商标注册'
            DetailModalRef.current.showModal(record)
          }}>
          {text}
        </span>
      )
    },
    {
      title: '商标状态',
      dataIndex: 'brandState'
    },
    {
      title: '国际分类',
      dataIndex: 'classify'
    },
    {
      title: '申请/注册号',
      dataIndex: 'regCode'
    },
    {
      title: '申请日期',
      dataIndex: 'applDate'
    }
  ]
  const { pagination } = useNewPage(callList)
  const [data, setdata] = useState([])
  const [iscount, setiscount] = useState('')
  const DetailModalRef = useRef<any>({})
  const [isShow, setIsShow] = useState(false)

  function callList() {
    return postCompanyInfoDetailBrandInfoPageList({
      pageNo: pagination.current,
      pageSize: pagination.pageSize,
      companyCode: companyCode || '0db17aea9cbdb7c35fd9f3fafd7ad626'
    }).then((res: { data: { list: SetStateAction<never[]>; total: any } }) => {
      setdata(res.data.list)
      res.data.total = Number(res.data.total) > 10000 ? 10000 : res.data.total
      setIsShow(res.data.total ? true : false)
      setiscount(res.data.total ?? '')
      hiddenModule(res.data.total ?? '') //总条数 传给父组件
      return res.data
    })
  }

  return (
    <>
      {isShow && (
        <div className="intellectual-property-trademark-wrapper" id="商标信息" data-count={iscount}>
          <h3 className="mb-4">商标信息</h3>
          <HsAdminTablePage
            columns={columns}
            dataSource={data}
            id="intellectual-property-trademark"
            pagination={pagination}
            rowKey={(record: { id: string }) => record.id}
            size="small"
          />
          <DetailModal ref={DetailModalRef} />
        </div>
      )}
    </>
  )
}

export default Patent
